package com.example.javapoint.threads.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolExample {
    public static void main(String[] args) {
        ExecutorService executors = Executors.newFixedThreadPool(5); // 创建线程池固定容量为5

        for (int i = 0; i < 10; i++) {
            WorkerThread workerThread = new WorkerThread("" + i);
            executors.execute(workerThread);
        }

        executors.shutdown(); // 使用完成关闭线程池
        while (!executors.isTerminated()) {}
        System.out.println("所有线程完成任务");
    }
}
